package com.jinxinol.basic.system.web;

import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.logging.Log;
import com.jinxinol.basic.system.domain.SysSetInfo;
import com.jinxinol.basic.system.service.ISysSetInfoService;
import com.jinxinol.core.common.BaseAction;
import com.jinxinol.core.common.ContextHelper;
import com.jinxinol.core.common.PageModel;
/**
 * 
 * @company Jinxin Computer Corp.
 * @author Conner
 * @email 764828388@qq.com
 * @description 系统消息设置Action
 * @date 2012-9-9
 */
public class SysSetInfoAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	private static final Log logger = ContextHelper.getLogger(SysSetInfoAction.class);
	private SysSetInfo sysSetInfo = new SysSetInfo();
	private PageModel<SysSetInfo> pm = new PageModel<SysSetInfo>();
	private List<SysSetInfo> listSysSetInfo;
	private String idStr;
	private String type;  //detail | edit
	private int i = 0;
	
	@Resource 
	ISysSetInfoService sysSetInfoService;
	
	public SysSetInfoAction(){}
	
	/**
	 * 添加系统消息设置
	 * */
	public String add(){
		try {
			sysSetInfoService.insert(sysSetInfo);
			return "addSuccess";
		} catch (Exception e) {
			logger.error("新增系统消息设置" + sysSetInfo.getbCode() + "失败", e);
			return ERROR;
		}
	}
	
	/**
	 * 查询系统消息设置
	 */
	public String findOneByBcode(){
		try {
			listSysSetInfo = sysSetInfoService.find(sysSetInfo);  //查询所有系统消息设置
			if(listSysSetInfo.size() > 0){
				sysSetInfo = listSysSetInfo.get(0);
			}
			if(type.equals("detail")){
				return "qurSuccess";
			}else if(type.equals("edit")){
				return "qurSuccess2";
			}else{
				return "qurSuccess";
			}
		} catch (Exception e) {
			logger.error("查询所有系统消息设置失败", e);
			return ERROR;
		}
	}
	
	/**
	 * 删除系统消息设置
	 * */
	public String delete(){
		String[] arr = null;
		try {
			if(!idStr.equals("")){
				arr = idStr.split(",");
				for(i = 0; i < arr.length ; i++){
					sysSetInfo = new SysSetInfo();
					sysSetInfo.setbCode(arr[i]);
					sysSetInfoService.delete(sysSetInfo);
				}
			}
			logger.info("删除系统消息设置成功！");
			return "delSuccess";
		} catch (Exception e) {
			logger.error("删除系统消息设置出现异常", e);
			return ERROR;
		}
	}
	
	/**
	 * 修改系统消息设置
	 * */
	public String update(){
		try {
			System.out.println("cueTime="+sysSetInfo.getCueTime());
			sysSetInfoService.update(sysSetInfo);
			return "updSuccess";
		} catch (Exception e) {
			logger.error("修改系统消息设置" + sysSetInfo.getbCode() + "出现异常！", e);
			return ERROR;
		}
	}
	
	/**
	 * 修改系统消息设置状态
	 * */
	public void updateSysSetInfoStatus(){
		try {
			sysSetInfoService.update(sysSetInfo);
			jsonObject.put(RESULT_CODE, SUCCESS);
		} catch (Exception e) {
			logger.error("修改系统消息设置" + sysSetInfo.getbCode() + "状态出现异常！", e);
			jsonObject.put(RESULT_CODE, ERROR);
			jsonObject.put(RESULT_MSG, "改变系统消息设置状态失败，请联系管理员！");
		}
		this.pushJsonResult();
	}
	
	/**
	 * 按条件查询系统消息设置
	 * */
	public String selectSysSetInfo(){
		try {
			pm = sysSetInfoService.findOnPage(sysSetInfo, pm);
			listSysSetInfo = sysSetInfoService.find(sysSetInfo);  //查询所有系统消息设置信息
			return "list";
		} catch (Exception e) {
			logger.error("按条件查询系统消息设置出现异常", e);
			return ERROR;
		}
	}
	
	/**
	 * 检查"类型编号"是否已存在
	 */
	public void checkBcode(){
		try {
			listSysSetInfo = sysSetInfoService.find(sysSetInfo);
			if(listSysSetInfo.size() > 0){
				jsonObject.put(RESULT_MSG, "yes");
			}else{
				jsonObject.put(RESULT_MSG, "no");
			}
		} catch (Exception e) {
			logger.error("检查类型编号是否已存在出现异常！", e);
			jsonObject.put(RESULT_CODE, ERROR);
			jsonObject.put(RESULT_MSG, "检查类型编号是否已存在失败，请联系管理员！");
		}
		this.pushJsonResult();
	}

	//getter & setter
	public SysSetInfo getSysSetInfo() {
		return sysSetInfo;
	}

	public void setSysSetInfo(SysSetInfo sysSetInfo) {
		this.sysSetInfo = sysSetInfo;
	}

	public PageModel<SysSetInfo> getPm() {
		return pm;
	}

	public void setPm(PageModel<SysSetInfo> pm) {
		this.pm = pm;
	}

	public List<SysSetInfo> getListSysSetInfo() {
		return listSysSetInfo;
	}

	public void setListSysSetInfo(List<SysSetInfo> listSysSetInfo) {
		this.listSysSetInfo = listSysSetInfo;
	}

	public String getIdStr() {
		return idStr;
	}

	public void setIdStr(String idStr) {
		this.idStr = idStr;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	
	
}
